package com.ssmTest.service.impl;

import com.google.gson.Gson;
import com.ssmTest.dao.IInterviewsDao;
import com.ssmTest.dao.IOrderDao;
import com.ssmTest.model.Interviews;
import com.ssmTest.model.Order;
import com.ssmTest.model.Result;
import com.ssmTest.service.DateTimeService;
import com.ssmTest.service.IInterviewsService;
import com.ssmTest.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("interviewsService")
public class InterviewsServiceImpl implements IInterviewsService {
    @Resource
    private IInterviewsDao iInterviewsDao;
    @Autowired
    private IInterviewsService iInterviewsService;
    @Autowired
    private DateTimeService dateTimeService;

    public void insertInterviews(Interviews interviews) {
        iInterviewsDao.insertInterviews(interviews);
    }

    public List<Interviews> interviewsList(int toexamine) {
        List<Interviews> list = iInterviewsDao.interviewsList(toexamine);
        return list;
    }

    public List<Interviews> interviewsList() {
        List<Interviews> list = iInterviewsDao.interviewsLists();
        return list;
    }

    public Interviews selectInterviewsByID(int id) {
        return this.iInterviewsDao.selectInterviewsID(id);
    }

    public List<Interviews> selectInterviewsByDate(String startdate, String enddate) {
        List<Interviews> list = iInterviewsDao.selectInterviewsByDate(startdate, enddate);
        return list;
    }

    public int numberOfInterviews(String startdate, String enddate) {
        return this.iInterviewsDao.numberOfInterviews(startdate, enddate);
    }

    public Result preseInterview(String json) {
        Gson gson = new Gson();
        Interviews interviews = gson.fromJson(json, Interviews.class);
        Result result = new Result();
        interviews.setTime(dateTimeService.getTime());
        iInterviewsService.insertInterviews(interviews);
        result.setCode(1);
        return result;
    }

    public void delInterview(int id) {
        this.iInterviewsDao.delInterview(id);
    }

    public void updateInterview(Interviews interviews) {
        this.iInterviewsDao.updateInterview(interviews);
    }

    //更新remark
    public boolean updateInterviewReasion(int id, String remark) {
        if (iInterviewsService.selectInterviewsByID(id) == null)
            return false;
        this.iInterviewsDao.updateInterviewReasion(id, remark);
        return true;
    }

    public List<Interviews> selectInterviews(int second_party,int pagenum) {
        return iInterviewsDao.selectinterviews(second_party,(pagenum - 1) * 10, pagenum * 10);
    }
    public List<Interviews> selectInterview(int first_party,int pagenum) {
        return iInterviewsDao.selectinterview(first_party,(pagenum - 1) * 10, pagenum * 10);
    }

    public List<Interviews> selectByPersionalId(int personal_id){
        return this.iInterviewsDao.selectByPersionalId(personal_id);
    }
}
